<?php
 /*Template Name: All Project Updates
 */
 


get_header(); ?>

<div class="container" id="top_info">
	<div class="top-content">&nbsp;</div>
    <div class="top-curve">&nbsp;</div>
</div>


<div class="container">
	<?php 
		$sliders = get_post_meta($post->ID, 'dmci_sliders', true);
		$slider_title = get_post_meta($post->ID, 'dmci_slider_title', true);
		$slider_desc = get_post_meta($post->ID, 'dmci_slider_desc', true);
		if( $sliders ):
		$sliders = json_decode(htmlspecialchars_decode($sliders), true);
		
	?>
	

	<div class="page-slider-wrapper">
    <div class="page-slider">
		
		<?php foreach($sliders as $slide) :?>
        <div class="slide">
        	<img src="<?php echo $slide; ?>" alt="image1" />
        </div>		
		<?php endforeach;?>
        
    </div>
	<div class="slider-text">
        <div class="title"><?php echo $slider_title; ?></div>
     	<div class="desc"><?php echo $slider_desc; ?></div>
    </div>
    </div>
	<?php else: ?>
		<div class="page-filler">&nbsp;</div>
	<?php endif; ?>
    
    <div class="page-content no-padding">
   	
		<div class="news">
		<h3>Construction Updates</h3>
		
    	<?php
		$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
		$args = array(
			'post_type' => 'dmci_cons_update',
			'paged' => $paged,
			'meta_key' => 'cons_update_date',
			'orderby' => 'meta_value',
			'order' => 'DESC',
			'posts_per_page' => 9,
		);
		$query = new WP_Query( $args );
		while($query->have_posts() ):
			$query->the_post();
				$proj_permalink = get_permalink();
				$the_date = get_post_meta($post->ID, 'cons_update_date', true);
				$query_args = array(
					'connected_type' => 'projects_to_consupdate',
					'connected_items' => intval(get_the_ID()),        
					'nopaging' => true
				);
				$project_query = new WP_Query($query_args);
				
				if($project_query->have_posts()):
					$project_query->the_post();
					?>
					<div class="news-block">
					<a href="<?php echo $proj_permalink . '?p_id=' . $post->p2p_to; ?>">
					<?php echo get_the_post_thumbnail( $post->ID, array('120', '120') ); ?>
					<div class="update-info">
						<div class="date"><?php echo $the_date ? date("F-j-Y", strtotime($the_date) ) : ''; ?></div>
						<div class="title"><?php the_title();?></div>
					</div>
					</a>
					</div>
				<?php
				endif;
		endwhile;
		
		
		wp_reset_postdata();
		?>
		<div class="clear">&nbsp;</div>
    	</div>
			
		<div class="pagination">
		<?php
			$big = 999999999; // need an unlikely integer

			echo paginate_links( array(
				'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
				'format' => '?paged=%#%',
				'current' => max( 1, get_query_var('paged') ),
				'total' => $query->max_num_pages
			) );
		?>
 		</div>
        
  		
    </div>
   
</div>




<?php wp_reset_query(); ?>
<?php get_footer(); ?>